//
//  BaseTableViewController.swift
//  微博个人swift
//
//  Created by 李灏 on 16/2/1.
//  Copyright © 2016年 lh. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {

    //定义用户是否登录的标识 如果access_token不为nil就表示登录成功
    var useLogrin = AccountViewModel.sharedAccountViewModel.userLogin
    //访客视图
    var visitroLoginView: VisitorLoginView?
    override func loadView() {
        if useLogrin {
            super.loadView()
            print("登录成功")
        } else {
//             print("登录失败")
            //自定义访客视图
            visitroLoginView = VisitorLoginView()
            view = visitroLoginView
            //指定代理
            visitroLoginView?.visitorLoginViewDelegate = self
//            navigationController?.navigationBar.tintColor = UIColor.orangeColor()
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegist")
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
        }
    }
    func userWillLogin() {
        print("登录")
        let OAuth = OAuthViewController()
        let nav = UINavigationController(rootViewController: OAuth)
        presentViewController(nav, animated: true, completion: nil)
    }
    func userWillRegist() {
        print("注册")
    }
    //设置view大小
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

}
